﻿using IcicleFramework.Entities;
using Microsoft.Xna.Framework;

namespace IcicleFramework.Components.Actions.Movement
{
    public class DirectMovementAction : ImmediateAction
    {
        protected Vector2 MovementAmount { get; set; }

        public DirectMovementAction() { }

        public DirectMovementAction(DirectMovementAction old)
            : base(old)
        { }

        public override void Execute(IGameObject target, IActionData data = null, bool continuous = false)
        {
            //Pull out the action data that we need. We're looking for a Vector2 defining the movement amounts along each axis.
            if (data != null && data.Data.ContainsKey("movementAmount"))
            {
                MovementAmount = (Vector2) data.Data["movementAmount"];
            }

            base.Execute(target, data, continuous);
        }

        protected override void Execute(GameTime gameTime)
        {
            Target.Position += (MovementAmount * (float)gameTime.ElapsedGameTime.TotalSeconds);
            base.Execute(gameTime);
        }

        public override IAction DeepClone()
        {
            return new DirectMovementAction(this);
        }
    }
}
